/*
 * @Author: Muxi 916566446@qq.com
 * @Date: 2025-08-04 14:38:30
 * @LastEditors: Muxi 916566446@qq.com
 * @LastEditTime: 2025-08-17 21:33:46
 * @FilePath: /yh_core_flutter_project/lib/project/common/config/app_env_config.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

enum EnvType { dev, test, release, prod }

///防止调用歧义，_EnvConfig私有，只对外暴露EnvManager
extension _EnvConfig on EnvType {
  /// API基础地址
  String get apiBaseUrl {
    switch (this) {
      case EnvType.dev:
        return "http://192.168.167.28:8082";
      case EnvType.test:
        return "https://api.qiuguocloud.com/test/v1/app";
      case EnvType.release:
      case EnvType.prod:
        return "https://api.qiuguocloud.com/v1/app";
    }
  }

  /// MQTT设备连接地址
  String get mqttHost {
    switch (this) {
      case EnvType.dev:
      case EnvType.test:
        return 'wss://yun.simicloud.com:10443/ws/iot1';
      case EnvType.release:
      case EnvType.prod:
        return 'wss://yun.simicloud.com:10443/ws/iot1';
    }
  }

  /// MQTT端口
  int get mqttPort => 10443;
}


class EnvManager {
  /// 当前环境可配置，默认为生产环境
  /// ⚠️ 注意：此属性为静态属性，全局共享，代码修改时请谨慎！
  static EnvType currentEnv = EnvType.prod;

  /// 获取当前环境的API地址
  static String get appBaseUrl => currentEnv.apiBaseUrl;

  /// 获取当前环境的MQTT地址
  static String get mqttUrl => currentEnv.mqttHost;

  /// 获取当前环境的MQTT端口
  static int get mqttPort => currentEnv.mqttPort;

  /// 获取指定环境的配置
  static String getBaseApiUrl(EnvType env) => env.apiBaseUrl;
  static String getBaseMqttUrl(EnvType env) => env.mqttHost;
  static int getBaseMqttPort(EnvType env) => env.mqttPort;
}
